package cn.wizzer.app.web.modules.controllers.platform.bus.bggl;

import cn.wizzer.app.bus.modules.models.YJbxx;
import cn.wizzer.app.bus.modules.models.YJbxxLcxx;
import cn.wizzer.app.bus.modules.services.YJbxxLcxxService;
import cn.wizzer.app.bus.modules.services.YJbxxService;
import cn.wizzer.app.sys.modules.models.Sys_unit;
import cn.wizzer.app.sys.modules.services.SysDictService;
import cn.wizzer.app.sys.modules.services.SysUnitService;
import cn.wizzer.app.sys.modules.services.SysUserService;
import cn.wizzer.app.web.commons.base.Globals;
import cn.wizzer.app.web.commons.slog.annotation.SLog;
import cn.wizzer.app.web.commons.utils.DateUtil;
import cn.wizzer.app.web.commons.utils.ShiroUtil;
import cn.wizzer.app.web.commons.utils.StringUtil;
import cn.wizzer.framework.base.Result;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.apache.commons.lang.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.nutz.aop.interceptor.ioc.TransAop;
import org.nutz.dao.Cnd;
import org.nutz.dao.Sqls;
import org.nutz.dao.entity.Record;
import org.nutz.ioc.aop.Aop;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.lang.Times;
import org.nutz.log.Log;
import org.nutz.log.Logs;
import org.nutz.mvc.annotation.At;
import org.nutz.mvc.annotation.Ok;
import org.nutz.mvc.annotation.Param;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;


/**
 * 报告二维码扫描  虞秀斌  2025-01
 */
@IocBean
public class GrCodeController {
    private static final Log log = Logs.get();
    @Inject
    private YJbxxService yjbxxService;
    @Inject
    private SysUnitService sysUnitService;
    @Inject
    private SysDictService sysDictService;
    @Inject
    private ShiroUtil shiroUtil;


    @At("/get-gr-code")
    @Ok("beetl:/platform/bus/bggl/grCodeDetail.html")
    @SLog(tag = "报告二维码扫描", msg = "样品:${args[0].qrCodeId}")
    public void printDo(@Param("qrCodeId") String qrCodeId, HttpServletRequest req) {
        YJbxx obj = yjbxxService.fetchLinks(yjbxxService.fetch(qrCodeId),"yjbxxjyxm", Cnd.NEW().asc("inspectionItemOrder"));
        if(obj!=null) {
            req.setAttribute("obj", JSONObject.fromObject(obj));
            req.setAttribute("yplxMap", JSONObject.fromObject(sysDictService.getCodeMap("yplx")));
            req.setAttribute("zhMap", JSONObject.fromObject(sysDictService.getIdMap("zh")));
            req.setAttribute("xzqhMap", JSONObject.fromObject(sysDictService.getIdMap("xzqh")));
            req.setAttribute("ypczMap", JSONObject.fromObject(sysDictService.getIdMap("ypcz")));
            req.setAttribute("jylxMap", JSONObject.fromObject(sysDictService.getCodeMap("jylx")));
            req.setAttribute("lcztMap", JSONObject.fromObject(sysDictService.getCodeMap("lczt")));
            req.setAttribute("lzztMap", JSONObject.fromObject(sysDictService.getCodeMap("lzzt")));

            req.setAttribute("storageMap", JSONObject.fromObject(sysDictService.getIdMap("storage")));
            req.setAttribute("informationMap", JSONObject.fromObject(sysDictService.getIdMap("information")));
            req.setAttribute("intentionMap", JSONObject.fromObject(sysDictService.getIdMap("intention")));
            req.setAttribute("exteriorMap", JSONObject.fromObject(sysDictService.getIdMap("exterior")));
            req.setAttribute("base", Globals.AppDomain);
            sysUnitService.fetch(Cnd.where("aliasName","!=","System").and("parentId","=",null));
            List<Sys_unit> sysUnitList = sysUnitService.listEntity(Sqls.create("select * from sys_unit where aliasName !='System' and  (parentId is null or parentId = '') and delFlag = 0 and hasChildren = 1"));
            req.setAttribute("unitName", sysUnitList.size()>0?sysUnitList.get(0).getName():null);
        }
    }
}
